package com.opengw.configuration;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opengw.configuration.route.Route;
import com.opengw.configuration.services.RouteService;

@Component
@Scope("singleton")
@Qualifier("initializer")
public class Initializer {

	private static boolean initialized = false;
	private static boolean initializedPostConstruct = false;
	@Autowired
	private RouteService routeService;

	private Initializer() {
		if (!initialized) {
			System.out.println("*********CONS***********");
			initialized = true;
			ConfigurationManager configurationManager = ConfigurationManager
					.getConfigurationManager();
			CertificateManager certificateManager = CertificateManager
					.getCertificateManager();
		}
	}

	@PostConstruct
	private void init() {
		if(initialized && !initializedPostConstruct){
			initializedPostConstruct = true;
			System.out.println("*********PSOT***********");
			try {
				if (routeService != null) {
					Route route = routeService.loadRoute(2);
					if (route != null) {
						System.out.println(route.getRouteURL());
					}
				} else {
	
					System.out.println("*********ROUTE***********");
	
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

}
